<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<button>按钮1</button>
		<button>按钮2</button>
		<button>按钮3</button>
		<button>按钮4</button>
		<button>按钮5</button>
		<button>按钮6</button>
		<button>按钮7</button>
		<button>按钮8</button>
		<button>按钮9</button>
		<button>按钮10</button>
		<script type="text/javascript">
			// var buttons = document.querySelectorAll("button")
			// for(var i = 1; i <= buttons.length; i++) {
			//     (function(k){
			// 		buttons[k-1].onclick = function() {
			// 			console.log(k);
			// 		}
			//     })(i)
			// }
			
			var buttons = document.querySelectorAll("button")
			for(let i = 1; i <= buttons.length; i++) {
			    
					buttons[i-1].onclick = function() {
						console.log(i);
					}
			    
			}
		</script>
	</body>
</html>
